package com.kh.pajx.sop.view.action;


import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.kh.pajx.sop.base.DatabaseContextHolder;
import com.kh.pajx.sop.base.ModelDrivenBaseAction;
import com.kh.pajx.sop.base.SOPConfig;
import com.kh.pajx.sop.domain.BossEcinfo;
import com.kh.pajx.sop.domain.HsSchoolInfo;
import com.kh.pajx.sop.domain.HsSchoolRelation;
import com.kh.pajx.sop.domain.SysArea;
import com.kh.pajx.sop.domain.SysDepartment;
import com.kh.pajx.sop.domain.SysDictionary;
import com.kh.pajx.sop.domain.SysInsideUser;
import com.kh.pajx.sop.domain.SysOutsideUser;
import com.kh.pajx.sop.util.common.ChineseToEnglish;
import com.kh.pajx.sop.util.common.DwzAjaxResult;
import com.kh.pajx.sop.util.common.FormatDate;
import com.kh.pajx.sop.util.common.JsonUtils;
import com.kh.pajx.sop.util.common.ValidatorUtils;
import com.kh.pajx.sop.util.page.QueryHelper;
import com.opensymphony.xwork2.ActionContext;

/**
 * 学校信息Struts2控制器
 * @author:	azzcsimp
 * @Createdate:	2014年7月24日 下午4:16:18
 */
@Controller
@Scope("prototype")
public class HsSchoolAction extends ModelDrivenBaseAction<HsSchoolInfo> {

	private static final long serialVersionUID = -4388501137709974573L;
	
	/** 学校扩展信息对象 */
	private HsSchoolRelation schoolRelation;
	
	/** 部门编码 */
	private String deptCode;
	
	/** 区县编码 */
	private String countyCode;
	
	/**
	 * @throws Exception */
	public String list() throws Exception{
		// ==>1.1  准备集团客户信息
		/*List<BossEcinfo> bossEcinfoList = bossEcinfoService.findAll();
		ActionContext.getContext().put("bossEcinfoList", bossEcinfoList);
		
		// ==>1.2  准备移动客户经理
		List<SysOutsideUser> mobManagerList = sysOutsideUserService.findUserListByType(1);
		ActionContext.getContext().put("mobManagerList", mobManagerList);*/
		
		// ==>1.3  准备扩展人员和维护人员信息 实际等于查询市场部下面人员
		List<SysInsideUser> saleList = sysInsideUserService.findUserByGroup(SOPConfig.CODE_USER_GROUP_SALE);
		ActionContext.getContext().put("saleList", saleList);
		
		// ==>1.4  准备激励方式
		List<SysDictionary> blanceTypeList=sysDictionaryService.findDicListByType(SOPConfig.DIC_CODE_BLANCETYPE);
		ActionContext.getContext().put("blanceTypeList", blanceTypeList);
				
		// ==>1.5  准备结算方式
		List<SysDictionary> marketingTypeList=sysDictionaryService.findDicListByType(SOPConfig.DIC_CODE_MARKETINGTYPE);
		ActionContext.getContext().put("marketingTypeList", marketingTypeList);
		
		// ==>1.6  准备市场部门
		List<SysDepartment> deptList =new ArrayList<SysDepartment>();
		if(getCurrentUser().getUserRole().getUsrDataRange()==0){
			//全部数据权限，查询所有销售部门
			deptList= sysDepartmentService.findChildrenDepartment(SOPConfig.CODE_DEPT_SALE);
		}else{
			//部门数据权限或个人权限，查询本部门
			deptList.add(sysDepartmentService.getByCode(getCurrentUser().getDepartment().getDeptCode()));
		}
		ActionContext.getContext().put("deptList", deptList);
		
		// ==>1.7 用于查询后区县的回显
		/*if(StringUtils.isNotEmpty(model.getAreaCode())){
			List<SysArea> countyList = sysAreaService.findAreaByCity(model.getAreaCode());
			ActionContext.getContext().put("countyList", countyList);
		}*/
		return "list";
	}
	/** 学校列表 */
	public String search(){
		
		try {
			// ==========参数校验===============
			validatePropertitysBySearch(model);
			//使用局部刷新，不需再准备回显信息
			
			// =====>1.初始化回显信息=============================================
			
			// ==>1.1  准备集团客户信息
			List<BossEcinfo> bossEcinfoList = bossEcinfoService.findAll();
			ActionContext.getContext().put("bossEcinfoList", bossEcinfoList);
			
			// ==>1.2  准备移动客户经理
			List<SysOutsideUser> mobManagerList = sysOutsideUserService.findUserListByType(1);
			ActionContext.getContext().put("mobManagerList", mobManagerList);
			
			// ==>1.3  准备扩展人员和维护人员信息 实际等于查询市场部下面人员
			List<SysInsideUser> saleList = sysInsideUserService.findUserByGroup(SOPConfig.CODE_USER_GROUP_SALE);
			ActionContext.getContext().put("saleList", saleList);
			
			// ==>1.4  准备激励方式
			List<SysDictionary> blanceTypeList=sysDictionaryService.findDicListByType(SOPConfig.DIC_CODE_BLANCETYPE);
			ActionContext.getContext().put("blanceTypeList", blanceTypeList);
					
			// ==>1.5  准备结算方式
			List<SysDictionary> marketingTypeList=sysDictionaryService.findDicListByType(SOPConfig.DIC_CODE_MARKETINGTYPE);
			ActionContext.getContext().put("marketingTypeList", marketingTypeList);
			
			// ==>1.6  准备市场部门
			/*List<SysDepartment> deptList =new ArrayList<SysDepartment>();
			if(getCurrentUser().getUserRole().getUsrDataRange()==0){
				//全部数据权限，查询所有销售部门
				deptList= sysDepartmentService.findChildrenDepartment(SOPConfig.CODE_DEPT_SALE);
			}else{
				//部门数据权限或个人权限，查询本部门
				deptList.add(sysDepartmentService.getByCode(getCurrentUser().getDepartment().getDeptCode()));
			}
			ActionContext.getContext().put("deptList", deptList);
			
			// ==>1.7 用于查询后区县的回显
			if(StringUtils.isNotEmpty(model.getAreaCode())){
				List<SysArea> countyList = sysAreaService.findAreaByCity(model.getAreaCode());
				ActionContext.getContext().put("countyList", countyList);
			}*/
			
			// =====>2.根据当前用户信息获取学校列表========================================
			hsSchoolInfoService.findSchoolListByUser(model, getDeptCode(), getCurrentUser(), getPageNum(), getNumPerPage());
		} catch (Exception e) {
			e.printStackTrace();
			ActionContext.getContext().put("errorMsg", "检索失败！"+e.getMessage());
		}
/*		
		
		
		
		
		//准备维护人员
		List<SysInsideUser> maintainList=sysInsideUserService.getUserByRoleCode(SOPConfig.CODE_USER_GROUP_MAINTAIN,1);
		// 准备销售人员 
		List<SysInsideUser> saleList =new ArrayList<SysInsideUser>();
		if(getCurrentUser().getUserRole().getUsrDataRange()==0){//全部数据权限，查询所有销售人员
			saleList= sysInsideUserService.getUserByGroupCode(SOPConfig.CODE_USER_GROUP_SALE);
		}else if(getCurrentUser().getUserRole().getUsrDataRange()==1){//部门数据权限，查询本部门下的销售人员
			saleList=sysInsideUserService.getUserByDeptCode(getCurrentUser().getDepartment().getDeptCode());
		}else{
			saleList.add(sysInsideUserService.getById(getCurrentUser().getUserId()));
		}
		ActionContext.getContext().put("saleList", saleList);
		
		ActionContext.getContext().put("maintainList", maintainList);
		
		// 准备销售部门
		List<SysDepartment> deptList =new ArrayList<SysDepartment>();
		if(getCurrentUser().getUserRole().getUsrDataRange()==0){//全部数据权限，查询所有销售部门
			deptList= sysDepartmentService.findChildrenDepartment(SOPConfig.CODE_DEPT_SALE);
		}else{//部门数据权限或个人权限，查询本部门
			deptList.add(sysDepartmentService.getByCode(getCurrentUser().getDepartment().getDeptCode()));
		}
		ActionContext.getContext().put("deptList", deptList);
		
		
		
		String userList = "";
		if(StringUtils.isNotEmpty(deptCode)){
			List<SysInsideUser> tempUserList = sysInsideUserService.getUserByDeptCode(deptCode);
			if(tempUserList!=null && tempUserList.size()>0){
				for (int i = 0; i < tempUserList.size(); i++) {
					if(i > 0){
						userList += ",";
					}
					userList += "'"+tempUserList.get(i).getIsuId()+"'";
				}
				userList = "("+userList+")";
			}else{
				userList = "('')";
			}
		}
		//用于查询后区县的回显
		if(StringUtils.isNotEmpty(model.getAreaCode())){
			List<SysArea> countyList = sysAreaService.findAreaByCity(model.getAreaCode());
			ActionContext.getContext().put("countyList", countyList);
		}
		if(getCurrentUser().isLookAll()){
			// 准备分页信息
			new QueryHelperForManyTable(HsSchoolInfo.class, "school")
				//.addTable(HsSchoolRelation.class, "relation")
				.addColumns()
				//.addColumns(1)
				//.addColumns(0,"sclId",1,"sclId")
				// 学校名称查询条件
				.addCondition(StringUtils.isNotEmpty(StringUtils.trim(model.getSclName())), "sclName like ?","%"+StringUtils.trim(model.getSclName())+"%")
				// 地区编码查询条件
				.addCondition(StringUtils.isNotEmpty(model.getAreaCode()), "areaCode = ?",model.getAreaCode())
				//区县编码查询条件
				.addCondition(StringUtils.isNotEmpty(model.getCountyCode()), "countyCode = ?",model.getCountyCode())
				// 部门编码查询条件
				.addCondition(StringUtils.isNotEmpty(deptCode), 0, "saleUserId in "+userList)
				// 结算方式
				.addCondition(StringUtils.isNotEmpty(model.getCheckStatusFlag()),0,"checkStatusFlag=?",model.getCheckStatusFlag())//审核状态
				.addCondition(StringUtils.isNotEmpty(model.getBalanceTypeFlag()),0, "balanceTypeFlag = ?",model.getBalanceTypeFlag())
				.addCondition(StringUtils.isNotEmpty(model.getSaleUserId()),0, "saleUserId=?",model.getSaleUserId())//销售人员ID
				.addCondition(StringUtils.isNotEmpty(model.getSclNumber()), 0, "sclNumber=?",model.getSclNumber())
				//.addCondition(0,"checkStatusFlag=?","1")
				.addCondition(0, "sclStatusFlag=?","1")
				//.addCondition(1, "relationStatusFlag=?","1")
				.preparePageBean(hsSchoolInfoService, pageNum, numPerPage);
		}else{
			if(getCurrentUser().getSclIdList()!=null && getCurrentUser().getSclIdList().size()>0){
				// 准备分页信息
				new QueryHelperForManyTable(HsSchoolInfo.class, "school")
					.addTable(HsSchoolRelation.class, "relation")
					.addColumns()
					.addColumns(0,"sclId",1,"sclId")
					// 学校名称查询条件
					.addCondition(StringUtils.isNotEmpty(StringUtils.trim(model.getSclName())), "sclName like ?","%"+StringUtils.trim(model.getSclName())+"%")
					// 地区编码查询条件
					.addCondition(StringUtils.isNotEmpty(model.getAreaCode()), "areaCode = ?",model.getAreaCode())
					// 区县编码查询条件
					.addCondition(StringUtils.isNotEmpty(model.getCountyCode()), "countyCode = ?",model.getCountyCode())
					// 部门编码查询条件
					.addCondition(StringUtils.isNotEmpty(deptCode), 1, "saleUserId in "+userList)
					// 结算方式
					.addCondition(StringUtils.isNotEmpty(model.getCheckStatusFlag()),0,"checkStatusFlag=?",model.getCheckStatusFlag())//审核状态
					.addCondition(StringUtils.isNotEmpty(model.getBalanceTypeFlag()),1, "balanceTypeFlag = ?",model.getBalanceTypeFlag())
					.addCondition(StringUtils.isNotEmpty(model.getBalanceTypeFlag()),1, "isuId=?",model.getBalanceTypeFlag())//销售人员ID
					//.addCondition(0,"checkStatusFlag=?","1")
					.addCondition(StringUtils.isNotEmpty(model.getSclNumber()), 0, "sclNumber=?",model.getSclNumber())
					.addCondition(0, "sclStatusFlag=?","1")
					.addCondition(1, "relationStatusFlag=?","1")
					.addConditionWithIn(0, "sclId","sclId",getCurrentUser().getSclIdList())
					.preparePageBean(hsSchoolInfoService, pageNum, numPerPage);
			}
		}*/
		
		return "scl_list";
	}
	
	
	public String getAllSaler(){
		Map request=(Map)ActionContext.getContext().get("request");
		deptCode=(String)request.get("deptCode");
		List<SysInsideUser> saleList=sysInsideUserService.getUserByDeptCode(deptCode);
		request.put("saleList", saleList);
		return "getAllSaler";
	}
	
	/** 添加页面 */
	public String addUI(){
		
		// 准备学校管理员信息
		//List<SysOutsideUser> sclManagerList = sysOutsideUserService.getUserByRoleCode(SOPConfig.CODE_USER_ROLE_SCHOOLMANAGER);
		//List<SysOutsideUser> sclManagerList = sysOutsideUserService.getUserByType(0,1);
		
		// 准备移动客户经理
		//List<SysOutsideUser> mobManagerList = sysOutsideUserService.getUserByRoleCode(SOPConfig.CODE_USER_ROLE_CHINAMOBILE);
		//List<SysOutsideUser> mobManagerList = sysOutsideUserService.getUserByType(1,1);
		
		// 准备扩展人员，原销售人员 
		List<SysInsideUser> saleList = sysInsideUserService.getUserByRoleCode(SOPConfig.CODE_USER_ROLE_EXTEND,1);
		
		// 准备维护人员 
		List<SysInsideUser> maintainList = sysInsideUserService.getUserByRoleCode(SOPConfig.CODE_USER_GROUP_MAINTAIN,1);
		
		// 准备客服人员
		List<SysInsideUser> customServiceList = sysInsideUserService.getUserByGroupCode(SOPConfig.CODE_USER_GROUP_CUSTOMERSERVICE,1);
		
		//准备激励方式
		List<SysDictionary> blanceTypeList=sysDictionaryService.getDicListByTypeCode(SOPConfig.DIC_CODE_BLANCETYPE);
		
		//准备结算方式
		List<SysDictionary> marketingTypeList=sysDictionaryService.getDicListByTypeCode(SOPConfig.DIC_CODE_MARKETINGTYPE);
		
		//ActionContext.getContext().put("sclManagerList", sclManagerList);
		//ActionContext.getContext().put("mobManagerList", mobManagerList);
		ActionContext.getContext().put("saleList", saleList);
		ActionContext.getContext().put("customServiceList", customServiceList);
		ActionContext.getContext().put("blanceTypeList", blanceTypeList);
		ActionContext.getContext().put("marketingTypeList", marketingTypeList);
		ActionContext.getContext().put("maintainList", maintainList);
		return "addUI";
	}

	/** 添加 */
	public void add(){
		DwzAjaxResult dwz = new DwzAjaxResult();
		try {
			model.setSclName(StringUtils.trim(model.getSclName())); // 学校名称
			model.setAreaCode(model.getAreaCode()); // 地区编码 省份2+地市2+
			model.setCountyCode(model.getCountyCode());//区县编码
			model.setSclPhone(StringUtils.trim(model.getSclPhone())); // 联系电话
			model.setSclAddr(StringUtils.trim(model.getSclAddr())); //地址
			model.setSclSummary(StringUtils.trim(model.getSclSummary())); // 学校简介
			model.setSclLeaderName(StringUtils.trim(model.getSclLeaderName())); // 学校联络人姓名
			model.setSclLeaderPhone(StringUtils.trim(model.getSclLeaderPhone())); // 学校联络人电话
			
			//String sclNumber = hsSchoolInfoService.getSchoolCodeByAreaCode(StringUtils.trim(model.getAreaCode()));
			String sclNumber = hsSchoolInfoService.getNextSchoolNumber();
			model.setSclNumber(sclNumber);  //学校代码，地区2+学校3 
			model.setSclSpell(hsSchoolInfoService.getSchoolSpell(model.getSclName()));
			model.setCardMap("1000000000000002"); // 保留区，不做加密处理
			// **************** 最后一次发送邀请时间，YYYYMMDDHHMMSS
			model.setSclStatusFlag("1");  // 信息状态标识，0-停用，1-正常
			model.setCheckStatusFlag("0"); // 审核状态标识，0-未审核，1-审核通过
			model.setInputTime(FormatDate.dateTimeDetail());  // 记录学校创建时间
			// hsSchoolInfoService.save(model);
			schoolRelation.setSclManagerId(schoolRelation.getSclManagerId()); // 学校管理员ID
			//schoolRelation.setSclId(model.getSclId()); // 学校编号
			schoolRelation.setMobManagerId(schoolRelation.getMobManagerId()); // 移动客户经理ID
			schoolRelation.setSaleUserId(schoolRelation.getSaleUserId()); // 负责该校的销售人员ID
			schoolRelation.setSaleKeepId(schoolRelation.getSaleKeepId());//维护人员Id
			//schoolRelation.setCsUserId(schoolRelation.getCsUserId()); // 负责该校的客服人员ID
			schoolRelation.setCardIssusrFlag(schoolRelation.getCardIssusrFlag()); // 发卡方标记，0-第三方，1-我方
			schoolRelation.setCardTypeFlag(schoolRelation.getCardTypeFlag()); // 卡类型标记，0-M1卡，1-射频卡
			schoolRelation.setMarketingTypeFlag(schoolRelation.getMarketingTypeFlag()); // 学校激励方式，0-无，1-现金，2-话费,3-其他
			schoolRelation.setBalanceTypeFlag(schoolRelation.getBalanceTypeFlag()); // 学校结算方式，0-不参与结算，1-13结算方式，2-14结算方式
			// 新添加学校信息 业务状态标记 设为停用，审核通过后打开
			//schoolRelation.setBizStatusFlag("0"); // 业务状态标记，0-停用，1-正常
			schoolRelation.setBizStatusFlag("1"); // 业务状态标记，0-停用，1-正常
			// 新添加学校信息 发送邀请开关设为不允许发送
			//schoolRelation.setInviteLockFlag("0"); // 发送邀请开关标记，0-不允许发送，1-允许发送
			schoolRelation.setInviteLockFlag("1"); // 发送邀请开关标记，0-不允许发送，1-允许发送
			schoolRelation.setIsExtend(1);  // 新增学校默认扩展
			schoolRelation.setRelationStatusFlag("1"); // 关联关系状态标识，0-废弃，1-正常
			schoolRelation.setRemark(schoolRelation.getRemark()); // 备注信息
			schoolRelation.setCreateTime(FormatDate.dateTimeDetail()); // 创建时间，YYYYMMDDHHMMSS
			schoolRelation.setCreateOperId(getCurrentUser().getUserId()); // 创建人员ID
			schoolRelation.setLimitTelareaFlag("1");//禁止拨打省外电话
			//("ORACLE函数获取学校流水号1：====》"+hsSchoolInfoService.getMaxSchoolCodeByAreaCode2(model.getAreaCode()));
			//("ORACLE函数获取学校流水号2：====》"+hsSchoolInfoService.getMaxSchoolCodeByAreaCode3(model.getAreaCode()));
			//("ORACLE函数获取学校流水号3：====》"+hsSchoolInfoService.getMaxSchoolCodeByAreaCode4(model.getAreaCode()));
			/*
			集团客户编码
			集团客户编码绑定时间，YYYYMMDDHHMMSS*/
			
			validatePropertitysByAdd(model);//安全校验
			validatePropertitysByAddSclRelation(schoolRelation);//安全校验
			hsSchoolInfoService.save(model, schoolRelation);
			dwz.setStatusCode("200");
			dwz.setMessage("添加成功！");
			dwz.setCallbackType("closeCurrent");
			//dwz.setNavTabId("school_list");
			dwz.setRel("show_scl_list");
			DwzAjaxResult.josnMessage(dwz);

		} catch (Exception e) {
			e.printStackTrace();
			dwz.setStatusCode("300");
			dwz.setMessage("添加失败！错误信息："+e.getMessage());
			DwzAjaxResult.josnMessage(dwz);
		}
	}
	
	/** 修改页面 */
	public String editUI(){
		// 准备学校管理员信息
		//List<SysOutsideUser> sclManagerList = sysOutsideUserService.getUserByRoleCode(SOPConfig.CODE_USER_ROLE_SCHOOLMANAGER);
		//List<SysOutsideUser> sclManagerList = sysOutsideUserService.getUserByType(0,1);
		
		// 准备移动客户经理
		//List<SysOutsideUser> mobManagerList = sysOutsideUserService.getUserByRoleCode(SOPConfig.CODE_USER_ROLE_CHINAMOBILE);
		//List<SysOutsideUser> mobManagerList = sysOutsideUserService.getUserByType(1,1);
		
		// 准备扩展人员，原销售人员 
		List<SysInsideUser> saleList = sysInsideUserService.getUserByRoleCode(SOPConfig.CODE_USER_ROLE_EXTEND,1);
				
		// 准备维护人员 
		List<SysInsideUser> maintainList = sysInsideUserService.getUserByRoleCode(SOPConfig.CODE_USER_GROUP_MAINTAIN,1);
		
		// 准备客服人员
		List<SysInsideUser> customServiceList = sysInsideUserService.getUserByGroupCode(SOPConfig.CODE_USER_GROUP_CUSTOMERSERVICE,1);
		
		//准备激励方式
		List<SysDictionary> blanceTypeList=sysDictionaryService.getDicListByTypeCode(SOPConfig.DIC_CODE_BLANCETYPE);
		//准备结算方式
		List<SysDictionary> marketingTypeList=sysDictionaryService.getDicListByTypeCode(SOPConfig.DIC_CODE_MARKETINGTYPE);
		
		HsSchoolRelation schoolRelation = hsSchoolRelationService.getBySclId(model.getSclId());
		ActionContext.getContext().put("schoolRelation", schoolRelation);
	
		ActionContext.getContext().put("saleList", saleList);
		ActionContext.getContext().put("customServiceList", customServiceList);
		ActionContext.getContext().put("blanceTypeList", blanceTypeList);
		ActionContext.getContext().put("marketingTypeList", marketingTypeList);
		ActionContext.getContext().put("maintainList", maintainList);
		
		
		HsSchoolInfo school = hsSchoolInfoService.getById(model.getSclId());
		
		//List<SysOutsideUser> sclManagerList = sysOutsideUserService.getUserByAreaCode(school.getAreaCode(), 0, 1);
		//List<SysOutsideUser> mobManagerList = sysOutsideUserService.getUserByAreaCode(school.getAreaCode(),1,1);
		List<SysOutsideUser> sclManagerList = sysOutsideUserService.getUserByCountyCode(school.getCountyCode(), 0, 1);
		List<SysOutsideUser> mobManagerList = sysOutsideUserService.getUserByCountyCode(school.getCountyCode(),1,1);
		//根据市查询区县
		List<SysArea> countyList=sysAreaService.findAreaByCity(school.getAreaCode());
		ActionContext.getContext().put("sclManagerList", sclManagerList);
		ActionContext.getContext().put("mobManagerList", mobManagerList);
		ActionContext.getContext().put("countyList", countyList);
		
		ActionContext.getContext().getValueStack().push(school);
		return "editUI";
	}
	
	public void edit(){
		DwzAjaxResult dwz = new DwzAjaxResult();
		try {
			// =====> 1.封装学校基本信息
			if(!ValidatorUtils.validateUUID(model.getSclId(), false)){
			   throw new Exception("学校编号输入不合法");
		     }
			HsSchoolInfo schoolInfo = hsSchoolInfoService.getById(model.getSclId());
			schoolInfo.setSclName(StringUtils.trim(model.getSclName())); // 学校名称
			schoolInfo.setAreaCode(model.getAreaCode()); // 地区编码 省份2+地市2+
			schoolInfo.setCountyCode(model.getCountyCode()); // 区县编码
			schoolInfo.setSclPhone(StringUtils.trim(model.getSclPhone())); // 联系电话
			schoolInfo.setSclAddr(StringUtils.trim(model.getSclAddr())); //地址
			schoolInfo.setSclSummary(StringUtils.trim(model.getSclSummary())); // 学校简介
			schoolInfo.setSclLeaderName(StringUtils.trim(model.getSclLeaderName())); // 学校联络人姓名
			schoolInfo.setSclLeaderPhone(StringUtils.trim(model.getSclLeaderPhone())); // 学校联络人电话
			//学校代码，地区2+学校3 
			model.setSclSpell(hsSchoolInfoService.getSchoolSpell(model.getSclName()));
			// 保留区，不做加密处理
			// **************** 最后一次发送邀请时间，YYYYMMDDHHMMSS
			model.setCheckStatusFlag("1"); // 审核状态标识，0-未审核，1-审核通过
			
			// =====> 2.封装学校扩展信息
			HsSchoolRelation temp = hsSchoolRelationService.getById(schoolRelation.getSclRelId());
			HsSchoolRelation relation = new HsSchoolRelation();
			BeanUtils.copyProperties(temp, relation);
			relation.setSclRelId(null);
			//relation.setSclId(model.getSclId()); // 学校编号
			relation.setMobManagerId(schoolRelation.getMobManagerId()); // 移动客户经理ID
			relation.setSclManagerId(schoolRelation.getSclManagerId()); // 学校管理员ID
			relation.setSaleUserId(schoolRelation.getSaleUserId()); // 负责该校的销售人员ID
			relation.setSaleKeepId(schoolRelation.getSaleKeepId()); // 负责该校的销售人员ID
			//relation.setCsUserId(schoolRelation.getCsUserId()); // 负责该校的客服人员ID
			relation.setCardIssusrFlag(schoolRelation.getCardIssusrFlag()); // 发卡方标记，0-第三方，1-我方
			relation.setCardTypeFlag(schoolRelation.getCardTypeFlag()); // 卡类型标记，0-M1卡，1-射频卡
			relation.setMarketingTypeFlag(schoolRelation.getMarketingTypeFlag()); // 学校激励方式，0-无，1-现金，2-话费,3-其他
			relation.setBalanceTypeFlag(schoolRelation.getBalanceTypeFlag()); // 学校结算方式，0-不参与结算，1-13结算方式，2-14结算方式
			// 新添加学校信息 业务状态标记 设为停用，审核通过后打开
			//relation.setBizStatusFlag("1"); // 业务状态标记，0-停用，1-正常 
			// 新添加学校信息 发送邀请开关设为不允许发送
			//relation.setInviteLockFlag("0"); // 发送邀请开关标记，0-不允许发送，1-允许发送
			relation.setRelationStatusFlag("1"); // 关联关系状态标识，0-废弃，1-正常
			relation.setRemark(schoolRelation.getRemark()); // 备注信息
			relation.setCreateTime(FormatDate.dateTimeDetail()); // 创建时间，YYYYMMDDHHMMSS
			relation.setCreateOperId(getCurrentUser().getUserId()); // 创建人员ID	
			
			//安全验证
			validatePropertitysByUpdate(schoolInfo);
			validatePropertitysByUpdateSclRelation(relation);
			hsSchoolInfoService.update(schoolInfo, relation);
			dwz.setStatusCode("200");
			dwz.setMessage("修改成功！");
			dwz.setCallbackType("closeCurrent");
			//dwz.setNavTabId("school_list");
			dwz.setRel("show_scl_list");
			DwzAjaxResult.josnMessage(dwz);
		} catch (Exception e) {
			e.printStackTrace();
			dwz.setStatusCode("300");
			dwz.setMessage("修改失败！错误信息："+e.getMessage());
			DwzAjaxResult.josnMessage(dwz);
		}
		
	}
	
	
	/** 学校快速检索 */
	public String suggest(){
		List schoolNameList = new ArrayList();
		List sclNameList=null;
		List<String> strList=new ArrayList<String>();
		if(!getCurrentUser().isLookAll()){
		}else{
			sclNameList=getCurrentUser().getSclIdList();
		}
		if(StringUtils.isNotEmpty(StringUtils.trim(model.getSclName()))){
			schoolNameList = hsSchoolInfoService.getSchoolNameListBySpell(model.getSclName(),sclNameList);
		}
		ActionContext.getContext().put("schoolNameList", schoolNameList);
		return "suggest";
	}
	
	/** 学校查找带回 */
	public String lookup(){
		try {
			// 准备地区信息
			List<SysArea> areaList = sysAreaService.findAll();
			List<SysArea> countyList=sysAreaService.findAreaByCity(model.getAreaCode());
			ActionContext.getContext().put("areaList", areaList);
			ActionContext.getContext().put("countyList", countyList);
			setNumPerPage(10);
			hsSchoolInfoService.findSchoolListByUser(model, getDeptCode(), getCurrentUser(), getPageNum(), numPerPage);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		/*if(getCurrentUser().isLookAll()){
			if(StringUtils.isEmpty(model.getSclName())) model.setSclName("");
			new QueryHelper(HsSchoolInfo.class, "school")
				.addCondition(StringUtils.isNotEmpty(model.getAreaCode()), "school.areaCode = ?",model.getAreaCode())
				.addCondition(StringUtils.isNotEmpty(model.getCountyCode()), "school.countyCode = ?",model.getCountyCode())
				.addCondition(StringUtils.isNotEmpty(model.getSclName()), "(school.sclName like ? or school.sclSpell like ?)","%"+model.getSclName()+"%","%"+model.getSclName().toUpperCase()+"%")
				//.addCondition("school.checkStatusFlag=?","1")
				.addCondition("school.sclStatusFlag=?","1")
				.addOrderProperty("school.sclNumber", true)
				.preparePageBean(hsSchoolInfoService, pageNum, numPerPage);
		}else{
			if(StringUtils.isEmpty(model.getSclName())) model.setSclName("");
			new QueryHelper(HsSchoolInfo.class, "school")
				.addCondition(StringUtils.isNotEmpty(model.getAreaCode()), "school.areaCode = ?",model.getAreaCode())
				.addCondition(StringUtils.isNotEmpty(model.getSclName()), "(school.sclName like ? or school.sclSpell like ?)","%"+model.getSclName()+"%","%"+model.getSclName().toUpperCase()+"%")
				//.addCondition("school.checkStatusFlag=?","1")
				.addCondition("school.sclStatusFlag=?","1")
				.addConditionWithIn("sclId",getCurrentUser().getSclIdList())
				.addOrderProperty("school.sclNumber", true)
				.preparePageBean(hsSchoolInfoService, pageNum, numPerPage);
		}*/
		return "lookup";
	}
	
	public void delete(){
		
	}
	
	/** 查看页面 */
	public String show(){
			try {
				// 准备地区信息
						List<SysArea> areaList = sysAreaService.findAll();
						// 准备学校管理员信息
						//List<SysOutsideUser> sclManagerList = sysOutsideUserService.getUserByRoleCode(SOPConfig.CODE_USER_ROLE_SCHOOLMANAGER);
						List<SysOutsideUser> sclManagerList = sysOutsideUserService.findUserListByType(0);
						
						// 准备移动客户经理
						//List<SysOutsideUser> mobManagerList = sysOutsideUserService.getUserByRoleCode(SOPConfig.CODE_USER_ROLE_CHINAMOBILE);
						List<SysOutsideUser> mobManagerList = sysOutsideUserService.findUserListByType(1);
						
						// 准备销售人员 
						List<SysInsideUser> saleList = sysInsideUserService.getUserByGroupCode(SOPConfig.CODE_USER_GROUP_SALE,1);
						// 准备维护人员 
						List<SysInsideUser> maintainList = sysInsideUserService.getUserByRoleCode(SOPConfig.CODE_USER_GROUP_MAINTAIN,1);
						// 准备客服人员
						List<SysInsideUser> customServiceList = sysInsideUserService.getUserByGroupCode(SOPConfig.CODE_USER_GROUP_CUSTOMERSERVICE,1);
						//准备激励方式
						List<SysDictionary> blanceTypeList=sysDictionaryService.getDicListByTypeCode(SOPConfig.DIC_CODE_BLANCETYPE);
						//准备结算方式
						List<SysDictionary> marketingTypeList=sysDictionaryService.getDicListByTypeCode(SOPConfig.DIC_CODE_MARKETINGTYPE);
						
						if(!ValidatorUtils.validateUUID(model.getSclId(), false)){
							throw new Exception("属性[学校编号]输入错误，非法提交！");
						}
						HsSchoolRelation schoolRelation = hsSchoolRelationService.getBySclId(model.getSclId());
						ActionContext.getContext().put("schoolRelation", schoolRelation);
						ActionContext.getContext().put("areaList", areaList);
						ActionContext.getContext().put("sclManagerList", sclManagerList);
						ActionContext.getContext().put("mobManagerList", mobManagerList);
						ActionContext.getContext().put("saleList", saleList);
						ActionContext.getContext().put("maintainList", maintainList);
						ActionContext.getContext().put("customServiceList", customServiceList);
						ActionContext.getContext().put("blanceTypeList", blanceTypeList);
						ActionContext.getContext().put("marketingTypeList", marketingTypeList);
						
						HsSchoolInfo school = hsSchoolInfoService.getById(model.getSclId());
						ActionContext.getContext().getValueStack().push(school);
						ActionContext.getContext().put("school", school);
						return "show";
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				ActionContext.getContext().put("errorMsg", "查询失败！"+e.getMessage());
				return null;
			}
	}
	

	/** 绑定集团客户页面 */
	public String bindEcinfoUI(){
		// 封装集团客户信息列表
		
		try {
			List<String> ecIdList= hsSchoolInfoService.getEcIdListByBind();//得到所有已绑定的集团客户id
			/*StringBuilder strEcId=new StringBuilder("(");
			for(int i=0;i<ecIdList.size();i++){
				strEcId.append("'"+ecIdList.get(i)+"'");
				if(i<ecIdList.size()-1){
					strEcId.append(",");
				}
			}
			strEcId.append(")");
			StringBuilder sb=new StringBuilder("");
			sb.append(" from BossEcinfo where ecId not in "+strEcId);
			List<BossEcinfo> ecinfoList = bossEcinfoService.findListByHql(sb.toString());
			System.out.println(ecinfoList.size());
			ActionContext.getContext().put("ecinfoList", ecinfoList);
			*/
			if(!ValidatorUtils.validateUUID(model.getSclId(), false)){
	    		throw new Exception("属性[学校编号]输入错误，非法提交！");
	    	}
			HsSchoolInfo school = hsSchoolInfoService.getById(model.getSclId());
			ActionContext.getContext().getValueStack().push(school);
			
			String ecName = ServletActionContext.getRequest().getParameter("ecName");
			if(!ValidatorUtils.validateSafeString(ecName, 256, true)){//可不填
	    		throw new Exception("属性[集团客户名称]输入错误，非法提交！");
	    	}
			QueryHelper queryHelper = new QueryHelper(BossEcinfo.class,"bi")
			.addCondition(StringUtils.isNotEmpty(StringUtils.trim(ecName)),"bi.ecName like ?", "%"+StringUtils.trim(ecName)+"%")
			.addConditionWithIn("bi.ecId","ecIds", ecIdList, false)
			.addOrderProperty("bi.ecName", true);
			queryHelper.preparePageBean(hsSchoolInfoService, pageNum, 10);
			ActionContext.getContext().put("ecName", ecName);
			return "bindEcinfoUI";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
	
	public void checkEcId(){
		DwzAjaxResult dwz = new DwzAjaxResult();
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			String ecName = request.getParameter("ecName");
			String sclName = request.getParameter("sclName");
			System.out.println("----开始校验ECID------");
			System.out.println("ecName:"+ecName);
			System.out.println("sclName:"+sclName);
			
			if(!ValidatorUtils.validateSafeString(ecName, 256, true)){
	    		throw new Exception("属性[集团客户名称]不符合规范，非法参数提交！");
	    	}
			if(!ValidatorUtils.validateSafeString(sclName, 80, true)){
	    		throw new Exception("属性[学校名称]不符合规范，非法参数提交！");
	    	}
			if(StringUtils.isNotEmpty(request.getParameter("ecId"))){
				if(sclName.contains(ecName) || ecName.contains(sclName)){
					dwz.setMessage("true");
				}else{
					dwz.setMessage("false");
				}
				dwz.setStatusCode("200");
				dwz.setRel(request.getParameter("ecId"));
				DwzAjaxResult.josnMessage(dwz);
			}else{
				dwz.setStatusCode("300");
				dwz.setMessage("校验失败！错误信息：无法获取集团客户ID！");
				DwzAjaxResult.josnMessage(dwz);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			dwz.setStatusCode("300");
			dwz.setMessage("校验失败！错误信息："+e.getMessage());
			DwzAjaxResult.josnMessage(dwz);
		}
	}
	
	/** 绑定集团客户 */
	public void bindEcinfo(){
		DwzAjaxResult dwz = new DwzAjaxResult();
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			if(!ValidatorUtils.validateFixedLengthNumber(request.getParameter("ecId"), 14, false)){//可不填
	    		throw new Exception("属性[集团客户编号]不符合规范，非法参数提交！");
	    	}
			if(StringUtils.isNotEmpty(request.getParameter("ecId"))){
				hsSchoolRelationService.bindEcinfo(model.getSclId(), request.getParameter("ecId"),getCurrentUser().getUserId());
				dwz.setStatusCode("200");
				dwz.setMessage("绑定成功！");
				dwz.setCloseDialog("school_bindEcinfoUI");
				//dwz.setNavTabId("school_list");
				dwz.setRel("show_scl_list");
				DwzAjaxResult.josnMessage(dwz);
			}else{
				dwz.setStatusCode("300");
				dwz.setMessage("绑定失败！错误信息：无法获取集团客户ID！");
				DwzAjaxResult.josnMessage(dwz);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			dwz.setStatusCode("300");
			dwz.setMessage("绑定失败！错误信息："+e.getMessage());
			DwzAjaxResult.josnMessage(dwz);
		}
	}
	
	public void removeEcid(){
		DwzAjaxResult dwz = new DwzAjaxResult();
		try {
			if(!ValidatorUtils.validateUUID(model.getSclId(), false)){//可不填
	    		throw new Exception("属性[学校编号]输入错误，非法提交！");
	    	}
			hsSchoolRelationService.removeEcid(model.getSclId(),getCurrentUser().getUserId());
			dwz.setStatusCode("200");
			dwz.setMessage("集团客户解绑成功！");
			//dwz.setNavTabId("school_list");
			dwz.setRel("show_scl_list");
			DwzAjaxResult.josnMessage(dwz);
		} catch (Exception e) {
			e.printStackTrace();
			dwz.setStatusCode("300");
			dwz.setMessage("解绑失败！错误信息："+e.getMessage());
			DwzAjaxResult.josnMessage(dwz);
		}
	}
	
	/**审核*/
	public void check(){
		DwzAjaxResult dwz = new DwzAjaxResult();
		HttpServletRequest request = ServletActionContext.getRequest();
		String sclId=request.getParameter("sclId");
		try {
			if(!ValidatorUtils.validateUUID(sclId, false)){//可不填
	    		throw new Exception("属性[学校编号]输入错误，非法提交！");
	    	}
			model=hsSchoolInfoService.getById(sclId);
			model.setCheckStatusFlag("1");
			hsSchoolInfoService.update(model);
			dwz.setStatusCode("200");
			dwz.setMessage("审核成功！");
			//dwz.setNavTabId("school_list");
			dwz.setRel("show_scl_list");
			DwzAjaxResult.josnMessage(dwz);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			dwz.setStatusCode("300");
			dwz.setMessage("审核失败！错误信息："+e.getMessage());
			DwzAjaxResult.josnMessage(dwz);
		}
	}
	
	/**查询各地区开通学校数量*/
	public void getDoCount(){
		try {
			HttpServletRequest request= ServletActionContext.getRequest();
			HttpServletResponse response = ServletActionContext.getResponse();
			//查询各地区开通学校数量
			List area_scl_count=schoolService.getSclCountByArea();
			String data=area_scl_count.toString();
			String ss=data.substring(1, data.length()-1);
			String scl_area="["+ss.replaceAll("\\[", "[\"").replaceAll(",", "\",").replaceAll("\\]\"", "]")+"]";
			//按部门查看开通学校数量
			List dept_scl_count=schoolService.getSclCountByDept();
			String data_dept=dept_scl_count.toString();
			String dc=data_dept.substring(1, data_dept.length()-1);
			String scl_dept="["+dc.replaceAll("\\[", "[\"").replaceAll(",", "\",").replaceAll("\\]\"", "]")+"]";
			//按类型查询设备数量
			int equ_attCount=schoolService.getEquCount("0");//考勤设备
			int equ_telCount=schoolService.getEquCount("1");//亲情电话
			JSONObject object = new JSONObject();
			object.put("area", scl_area);
			object.put("dept", scl_dept);
			object.put("equ_attCount", equ_attCount);
			object.put("equ_telCount", equ_telCount);
			JsonUtils.toJSON(object);
			response.setCharacterEncoding("UTF-8");
			PrintWriter o = null;
			try {
				o = response.getWriter();
			} catch (IOException e) {
				e.printStackTrace();
			}
			o.print(object.toString());
			o.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	/**首页统计图*/
	public void getReport(){
		try {
			
			HttpServletResponse response = ServletActionContext.getResponse();
			
			DatabaseContextHolder.setCustomerType(DatabaseContextHolder.DATA_SOURCE_DBAK);
			//统计在校生开通人数、毕业生开通人数
			List stuInOutOpenNum = schoolService.getstuInOutOpenNum();
			
			//--统计在校生各套餐分布情况
			List taocanNum = schoolService.gettaocanNum();
			
			//--在校生人数、在校生开通人数、毕业生人数、毕业生开通人数 
			List stuAllNum = schoolService.getstuAllNum();
			
			//--各部门截止当前开通人数
			List<List> deptOpenNum = schoolService.getdeptOpenNum();
			
			String dept="",deptNum="";
			for(int i=0;i<deptOpenNum.size();i++){
				dept+="'"+deptOpenNum.get(i).get(0)+"'";
				if(i!=deptOpenNum.size()-1){
					dept+=",";
				}
				deptNum+=deptOpenNum.get(i).get(1);
				if(i!=deptOpenNum.size()-1){
					deptNum+=",";
				}
			}
			//System.out.println(stuInOutOpenNum.get(0).toString()+">>>>  "+taocanNum.get(0).toString()+">>>>>  "+stuAllNum.get(0).toString()+">>>>>>  "+"["+dept+"]"+">>>>> "+"["+deptNum+"]");
			JSONObject object = new JSONObject();
			object.put("stuOpenNum",stuInOutOpenNum.get(0).toString() );
			object.put("taocanNum", taocanNum.get(0).toString());
			object.put("stuAllNum", stuAllNum.get(0).toString());
			object.put("dept", "["+dept+"]");
			object.put("deptNum", "["+deptNum+"]");
			response.setCharacterEncoding("UTF-8");
			PrintWriter o = response.getWriter();
			
			o.print(object.toString());
			//System.out.println(object.toString());
			o.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 *允许/限制拨打省外电话 
	 */
	public void allowPhone(){
		DwzAjaxResult dwz = new DwzAjaxResult();
		HttpServletRequest request = ServletActionContext.getRequest();
		String sclId=request.getParameter("sclId");
		String flag=request.getParameter("flag");
		try {
			if(!ValidatorUtils.validateUUID(sclId, false)){//可不填
	    		throw new Exception("属性[学校编号]输入错误，非法提交！");
	    	}
			if(!ValidatorUtils.validateFixedLengthNumber(flag, 1, true)){//可不填
	    		throw new Exception("属性[标示符]输入错误，非法提交！");
	    	}
			// =====> 1.封装学校基本信息
			HsSchoolInfo schoolInfo = hsSchoolInfoService.getById(sclId);//获得学校基本信息，其实不必，这是为了使用修改方法
			// =====> 2.封装学校扩展信息
			HsSchoolRelation temp = hsSchoolRelationService.getBySclId(sclId);
			HsSchoolRelation relation = new HsSchoolRelation();
			BeanUtils.copyProperties(temp, relation);
			relation.setSclRelId(null);
			//relation.setSclId(model.getSclId()); // 学校编号
			if("0".equals(flag)){
				relation.setLimitTelareaFlag("1");
			}else if("1".equals(flag)){
				relation.setLimitTelareaFlag("0");
			}
			relation.setRelationStatusFlag("1"); // 关联关系状态标识，0-废弃，1-正常
			relation.setCreateTime(FormatDate.dateTimeDetail()); // 创建时间，YYYYMMDDHHMMSS
			relation.setCreateOperId(getCurrentUser().getUserId()); // 创建人员ID
			
			hsSchoolInfoService.update(schoolInfo, relation);
			
			dwz.setStatusCode("200");
			dwz.setMessage("修改成功！");
			//dwz.setNavTabId("school_list");
			dwz.setRel("show_scl_list");
			DwzAjaxResult.josnMessage(dwz);
		} catch (Exception e) {
			e.printStackTrace();
			dwz.setStatusCode("300");
			dwz.setMessage("修改失败！错误信息："+e.getMessage());
			DwzAjaxResult.josnMessage(dwz);
		}
	}
	/**
	 *业务启用/停用 
	 */
	public void bizControl(){
		DwzAjaxResult dwz = new DwzAjaxResult();
		HttpServletRequest request = ServletActionContext.getRequest();
		String sclId=request.getParameter("sclId");
		String flag=request.getParameter("flag");
		try {
			if(!ValidatorUtils.validateUUID(sclId, false)){//可不填
	    		throw new Exception("属性[学校编号]输入错误，非法提交！");
	    	}
			if(!ValidatorUtils.validateFixedLengthNumber(flag, 1, true)){//可不填
	    		throw new Exception("属性[标示符]输入错误，非法提交！");
	    	}
			// =====> 1.封装学校基本信息
			HsSchoolInfo schoolInfo = hsSchoolInfoService.getById(sclId);//获得学校基本信息，其实不必，这是为了使用修改方法
			// =====> 2.封装学校扩展信息
			HsSchoolRelation temp = hsSchoolRelationService.getBySclId(sclId);
			HsSchoolRelation relation = new HsSchoolRelation();
			BeanUtils.copyProperties(temp, relation);
			relation.setSclRelId(null);
			//relation.setSclId(model.getSclId()); // 学校编号
			if("0".equals(flag)){
				relation.setBizStatusFlag("0");
			}else if("1".equals(flag)){
				relation.setBizStatusFlag("1");
			}
			relation.setRelationStatusFlag("1"); // 关联关系状态标识，0-废弃，1-正常
			relation.setCreateTime(FormatDate.dateTimeDetail()); // 创建时间，YYYYMMDDHHMMSS
			relation.setCreateOperId(getCurrentUser().getUserId()); // 创建人员ID
			
			hsSchoolInfoService.update(schoolInfo, relation);
			
			dwz.setStatusCode("200");
			dwz.setMessage("修改成功！");
			//dwz.setNavTabId("school_list");
			dwz.setRel("show_scl_list");
			DwzAjaxResult.josnMessage(dwz);
		} catch (Exception e) {
			e.printStackTrace();
			dwz.setStatusCode("300");
			dwz.setMessage("修改失败！错误信息："+e.getMessage());
			DwzAjaxResult.josnMessage(dwz);
		}
	}
	public String getAreaByCity(){
		Map request=(Map)ActionContext.getContext().get("request");
		DwzAjaxResult result = new DwzAjaxResult();
		List<SysArea> countyList = null;
		String areaCode=(String)request.get("areaCode");
		countyList = sysAreaService.findAreaByCity(areaCode);
		request.put("countyList", countyList);
		
		return "getCounty";
	}
	
	
	/**安全验证*/
	private void validatePropertitysByAdd(HsSchoolInfo demo)throws Exception{
    	if(!ValidatorUtils.validateRelativeSafeString(demo.getSclName(),80, false)){
    		throw new Exception("属性[学校名称]输入错误，非法提交！");
    	}
    	/*if(!ValidatorUtils.validateFixedLengthNumber(demo.getSclNumber(), 5, true)){
    		throw new Exception("属性[学校编号]输入错误，非法提交！");
    	}*/
    	if(!ValidatorUtils.validateRelativeSafeString(demo.getSclSummary(), 120, true)){
    		throw new Exception("属性[学校简介]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateFixedLengthNumber(demo.getAreaCode(), 4, false)){
    		throw new Exception("属性[地区编码]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateFixedLengthNumber(demo.getCountyCode(), 6, false)){
    		throw new Exception("属性[区县编码]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validatePhone(demo.getSclPhone(), true)){
    		throw new Exception("属性[联系电话]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateSafeString(demo.getSclLeaderName(), 30, true)){
    		throw new Exception("属性[联络人姓名]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validatePhone(demo.getSclLeaderPhone(), true)){
    		throw new Exception("属性[联络人电话]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateRelativeSafeString(demo.getSclSummary(), 2000, true)){
    		throw new Exception("属性[学校简介]输入错误，非法提交！");
    	}
    }
	private void validatePropertitysByUpdate(HsSchoolInfo demo)throws Exception{
		if(!ValidatorUtils.validateUUID(demo.getSclId(), false)){
    		throw new Exception("属性[学校名称]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateRelativeSafeString(demo.getSclName(),80, false)){
    		throw new Exception("属性[学校名称]输入错误，非法提交！");
    	}
    	/*if(!ValidatorUtils.validateFixedLengthNumber(demo.getSclNumber(), 5, true)){
    		throw new Exception("属性[学校编号]输入错误，非法提交！");
    	}*/
    	if(!ValidatorUtils.validateRelativeSafeString(demo.getSclSummary(), 120, true)){
    		throw new Exception("属性[学校简介]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateFixedLengthNumber(demo.getAreaCode(), 4, false)){
    		throw new Exception("属性[地区编码]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateFixedLengthNumber(demo.getCountyCode(), 6, false)){
    		throw new Exception("属性[区县编码]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validatePhone(demo.getSclPhone(), true)){
    		throw new Exception("属性[联系电话]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateSafeString(demo.getSclLeaderName(), 30, true)){
    		throw new Exception("属性[联络人姓名]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validatePhone(demo.getSclLeaderPhone(), true)){
    		throw new Exception("属性[联络人电话]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateRelativeSafeString(demo.getSclSummary(), 2000, true)){
    		throw new Exception("属性[学校简介]输入错误，非法提交！");
    	}
    }
	private void validatePropertitysByAddSclRelation(HsSchoolRelation demo)throws Exception{
    	if(!ValidatorUtils.validateUUID(demo.getMobManagerId(), false)){
    		throw new Exception("属性[移动客户经理]输入错误，非法提交！");
    	}
    	/*if(!ValidatorUtils.validateFixedLengthNumber(demo.getSclNumber(), 5, true)){
    		throw new Exception("属性[学校编号]输入错误，非法提交！");
    	}*/
    	if(!ValidatorUtils.validateUUID(demo.getSclManagerId(), true)){//可不填
    		throw new Exception("属性[学校管理员]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateUUID(demo.getSaleUserId(), true)){
    		throw new Exception("属性[扩展人员]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateUUID(demo.getSaleKeepId(), true)){
    		throw new Exception("属性[维护人员]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateFixedLengthNumber(demo.getCardTypeFlag(), 1, false)){
    		throw new Exception("属性[卡类型]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateFixedLengthNumber(demo.getCardIssusrFlag(), 1, false)){
    		throw new Exception("属性[发卡方]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateFixedLengthNumber(demo.getBalanceTypeFlag(), 1, false)){
    		throw new Exception("属性[结算方式]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateFixedLengthNumber(demo.getMarketingTypeFlag(), 1, false)){
    		throw new Exception("属性[激励方式]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateRelativeSafeString(demo.getRemark(), 200, true)){
    		throw new Exception("属性[备注]输入错误，非法提交！");
    	}
    }
	private void validatePropertitysByUpdateSclRelation(HsSchoolRelation demo)throws Exception{
		if(!ValidatorUtils.validateUUID(demo.getMobManagerId(), false)){
    		throw new Exception("属性[移动客户经理]输入错误，非法提交！");
    	}
    	/*if(!ValidatorUtils.validateFixedLengthNumber(demo.getSclNumber(), 5, true)){
    		throw new Exception("属性[学校编号]输入错误，非法提交！");
    	}*/
    	if(!ValidatorUtils.validateUUID(demo.getSclManagerId(), true)){//可不填
    		throw new Exception("属性[学校管理员]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateUUID(demo.getSaleUserId(), false)){
    		throw new Exception("属性[扩展人员]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateUUID(demo.getSaleKeepId(), true)){
    		throw new Exception("属性[维护人员]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateFixedLengthNumber(demo.getCardTypeFlag(), 1, false)){
    		throw new Exception("属性[卡类型]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateFixedLengthNumber(demo.getCardIssusrFlag(), 1, false)){
    		throw new Exception("属性[发卡方]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateFixedLengthNumber(demo.getBalanceTypeFlag(), 1, false)){
    		throw new Exception("属性[结算方式]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateFixedLengthNumber(demo.getMarketingTypeFlag(), 1, false)){
    		throw new Exception("属性[激励方式]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateRelativeSafeString(demo.getRemark(), 200, true)){
    		throw new Exception("属性[备注]输入错误，非法提交！");
    	}
    }
	private void validatePropertitysBySearch(HsSchoolInfo demo)throws Exception{
    	if(!ValidatorUtils.validateRelativeSafeString(demo.getSclName(),80, true)){
    		throw new Exception("属性[学校名称]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateFixedLengthNumber(demo.getSclNumber(), 5, true)){
    		throw new Exception("属性[学校编号]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateFixedLengthNumber(demo.getAreaCode(), 4, true)){
    		throw new Exception("属性[地区编码]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateFixedLengthNumber(demo.getCountyCode(), 6, true)){
    		throw new Exception("属性[区县编码]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateFixedLengthNumber(getDeptCode(), 4, true)){
    		throw new Exception("属性[部门编码]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateUUID(model.getSaleUserId(), true)){
    		throw new Exception("属性[市场人员编号]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateFixedLengthNumber(model.getBalanceTypeFlag(), 1, true)){
    		throw new Exception("属性[结算方式]输入错误，非法提交！");
    	}
    	if(!ValidatorUtils.validateFixedLengthNumber(model.getCheckStatusFlag(),1, true)){
    		throw new Exception("属性[审核状态]输入错误，非法提交！");
    	}
    }
	// ============================================================

	public HsSchoolRelation getSchoolRelation() {
		return schoolRelation;
	}

	public void setSchoolRelation(HsSchoolRelation schoolRelation) {
		this.schoolRelation = schoolRelation;
	}

	public String getDeptCode() {
		return deptCode;
	}

	public void setDeptCode(String deptCode) {
		this.deptCode = deptCode;
	}


	public String getCountyCode() {
		return countyCode;
	}


	public void setCountyCode(String countyCode) {
		this.countyCode = countyCode;
	}

	
	
	
}
